package com.imu.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import com.imu.commons.base.BaseController;
import com.imu.commons.utils.StringUtils;
import com.imu.model.Article;
import com.imu.service.IArticleService;

@Controller
public class IndexController extends BaseController {
	@Autowired
	IArticleService articleService;
	
	/**
     * 首页
     *
     * @return
     */
    @GetMapping("/")
    public String index() {
        return "redirect:/index";
    }

    /**
     * 首页
     *
     * @param model
     * @return
     */
    @GetMapping("/index")
    public String index(Model model) {
    	List<Article> news = articleService.indexNews();
    	List<Article> zckjs = articleService.indexZckjs();
    	model.addAttribute("news", news);
    	model.addAttribute("zckjs", zckjs);
        return "index";
    }
    
    /**
     * 众创空间
     *
     * @param model
     * @return
     */
    @GetMapping("/zckj")
    public String zckj(HttpServletRequest request,Model model) {
    	int totalPageNum = (articleService.zckjsNum()  +  9  - 1) / 9;
    	int page=1;
    	if(StringUtils.isNotBlank(request.getParameter("page"))) {
    		page = Integer.parseInt(request.getParameter("page"));
    	}
    	List<Article> zckjs = articleService.zckjList(page);
    	model.addAttribute("totalPageNum", totalPageNum);
    	model.addAttribute("zckjs", zckjs);
        return "front/zckj";
    }
    
    /**
     * 众创空间企业细节
     *
     * @param model
     * @return
     */
    @GetMapping("/zckjDetail")
    public String zckjDetail(HttpServletRequest request,Model model) {
    	int id=0;
    	if(StringUtils.isNotBlank(request.getParameter("id"))) {
    		id = Integer.parseInt(request.getParameter("id"));
    	}
    	Article zckj = articleService.zckjDetail(id);
    	model.addAttribute("zckj", zckj);
        return "front/zckjdetail";
    }

}
